package com.levy.contronller.javase.designModel.iterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 容器
 * Created by levy on 2018/8/1.
 */
public class BookList {

    private List<Book> bookList;

    private int index;

    public BookList() {
        this.bookList = new ArrayList<Book>();
    }

    public void addBook(Book book) {
        bookList.add(book);
    }

    public void deleteBook(Book book) {
        int i = bookList.indexOf(book);
        bookList.remove(i);
    }

//    public boolean hasNext(){
//        if (index >= bookList.size()){
//            return false;
//        }
//        return true;
//    }
//
//    public Book getNext(){
//        return bookList.get(index++);
//    }


//    public List<Book> getBookList() {
//
//        return bookList;
//
//    }

    public Iterator getIterator() {
        return new Itr();
    }

    private class Itr implements Iterator {


        @Override
        public boolean hasNext() {
            if (index >= bookList.size()) {
                return false;
            }
            return true;
        }

        @Override
        public Object next() {
            return bookList.get(index++);
        }

        @Override
        public void remove() {

        }

    }


}



